package com.qingcloud.fexecutor.controller;

import com.qingcloud.fexecutor.pojo.WebProjectDTO;
import com.qingcloud.fexecutor.service.WebPubAppService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

@Api(value = "页面管理相关接口", tags = "页面管理相关接口")
@RestController
@RequestMapping("/screen")
public class WebPageController {

    @Resource
    private WebPubAppService webPubAppService;

    @ApiOperation(value = "查询页面变量", notes = "保存页面变量")
    @GetMapping("/page/variable/{pageId}/{type}")
    public Map<String, Object> saveVariable(@PathVariable("pageId") Integer pageId,
                                            @PathVariable("type") Integer type) {
        return webPubAppService.findPageVariable(pageId);
    }

    @ApiOperation(value = "查询页面详情", notes = "查询页面详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageId", value = "页面ID",
                    required = true, dataTypeClass = Integer.class, paramType = "path", example = "1"),
            @ApiImplicitParam(name = "type", value = "应用类型 1-开发应用 2-商城应用 3-发布应用",
                    required = true, dataTypeClass = String.class, paramType = "path", example = "1"),
    })
    @GetMapping("/page/detail/{id}/{type}")
    public WebProjectDTO.WebPageDTO pageDetail(@PathVariable(value = "id") Integer id,
                                               @PathVariable("type") Integer type) {
        return webPubAppService.pageDetail(id);
    }

}
